package com.ruoyi.web.controller.inspection;

import java.util.List;

import com.ruoyi.inspection.domain.FzInspectionPlan;
import com.ruoyi.inspection.service.IFzInspectionPlanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划Controller
 * 
 * @author ruoyi
 * @date 2020-03-13
 */
@Controller
@RequestMapping("/inspection/plan")
public class FzInspectionPlanController extends BaseController
{
    private String prefix = "inspection/plan";

    @Autowired
    private IFzInspectionPlanService fzInspectionPlanService;

    @RequiresPermissions("inspection:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询计划列表
     */
    @RequiresPermissions("inspection:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzInspectionPlan fzInspectionPlan)
    {
        startPage();
        List<FzInspectionPlan> list = fzInspectionPlanService.selectFzInspectionPlanList(fzInspectionPlan);
        return getDataTable(list);
    }

    /**
     * 导出计划列表
     */
    @RequiresPermissions("inspection:plan:export")
    @Log(title = "计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzInspectionPlan fzInspectionPlan)
    {
        List<FzInspectionPlan> list = fzInspectionPlanService.selectFzInspectionPlanList(fzInspectionPlan);
        ExcelUtil<FzInspectionPlan> util = new ExcelUtil<FzInspectionPlan>(FzInspectionPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 新增计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存计划
     */
    @RequiresPermissions("inspection:plan:add")
    @Log(title = "计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzInspectionPlan fzInspectionPlan)
    {
        return toAjax(fzInspectionPlanService.insertFzInspectionPlan(fzInspectionPlan));
    }

    /**
     * 修改计划
     */
    @GetMapping("/edit/{planId}")
    public String edit(@PathVariable("planId") String planId, ModelMap mmap)
    {
        FzInspectionPlan fzInspectionPlan = fzInspectionPlanService.selectFzInspectionPlanById(planId);
        mmap.put("fzInspectionPlan", fzInspectionPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存计划
     */
    @RequiresPermissions("inspection:plan:edit")
    @Log(title = "计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzInspectionPlan fzInspectionPlan)
    {
        return toAjax(fzInspectionPlanService.updateFzInspectionPlan(fzInspectionPlan));
    }

    /**
     * 删除计划
     */
    @RequiresPermissions("inspection:plan:remove")
    @Log(title = "计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzInspectionPlanService.deleteFzInspectionPlanByIds(ids));
    }
}
